﻿using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Text;

using Common;
using Core.Alias;
using Core.TypeConvert;

namespace Core.Wapper.CSharpWapper
{
    public class ColumnWrapper
    {
        public ColumnInfo Column = null;
        public TableInfo Table = null;
        public TableWrapper TableWrapper = null;

        private DbCommandBuilder m_CommandBuilder = null;

        public ColumnWrapper(ColumnInfo columnInfo, TableWrapper tableWrapper)
        {
            this.Column = columnInfo;
            this.Table = columnInfo.Table;
            this.TableWrapper = tableWrapper;
            this.m_CommandBuilder = columnInfo.Table.SchemaHeler.DBFactory.CreateCommandBuilder();
        }

        public string Name
        {
            get
            {
                return this.Column.Name;
            }
        }

        public string DBType
        {
            get
            {
                return MSSqlDbTypeConverter.ToDbTypeString(this.Column.RealDB_Type);
            }
        }


        public string SystemType
        {
            get
            {
                return CSharpAlias.GetAlias(this.Column.System_Type);
            }
        }

        public string SystemTypeShortName
        {
            get
            {
                return Type.GetType(this.Column.System_Type).Name;
            }
        }

        public string PropName
        {
            get
            {
                return NameUltility.ToPascal(this.Column.Name);
            }
        }

        public string VarName
        {
            get
            {
                return NameUltility.ToCamel(this.Column.Name);
            }
        }

        public string QualifiedColumnName
        {
            get
            {
                return this.m_CommandBuilder.QuoteIdentifier(this.Column.Name);
            }
        }
    }
}
